package com.wss.day10.stream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/5/7
 */

    public class Test2 {
        public static void main(String[] args) {

            List<Integer> integerList = new ArrayList<>();
            Collections.addAll(integerList, 6, 7, 3, 8, 1, 2, 9);
            integerList.stream().filter(n -> n > 7).forEach(s -> System.out.println(s));

            // 3. 筛选员工中工资高于 8000 的人，并形成新的集合
            List<Employee> employees = new ArrayList<>();
            employees.add(new Employee("张三", 7000));
            employees.add(new Employee("李四", 9000));
            employees.add(new Employee("王五", 8500));
            List<Employee> highSalary = employees.stream()
                    .filter(e -> e.getSalary() > 8000)
                    .collect(Collectors.toList());
            System.out.println("工资高于 8000 的员工: " + highSalary);

            /*4. 获取 String 集合中最长的元素？？？？？？？？？
            Optional<String> longestOptional = Stream.of("王五", "哇哇哇哇", "伟大的", "王了").*/


            // 5. 获取 Integer 集合中最大值
            Optional<Integer> optionalI =Stream.of(6, 7, 3, 8, 1, 2, 9).reduce(Integer::max);
            Integer max= optionalI.orElse(0);
            System.out.println("集合中最大值:"+max);


            // 6. 获取员工工资最高的人 ？？？？？


            // 7. 计算 Integer 集合中大于 6 的元素的个数
            long count = integerList.stream().filter(n -> n > 6).count();
            System.out.println("大于 6 的元素个数: " + count);

            // 8. 将员工按照工资由低到高排序，显示名字
            List<String> list = employees.stream()
                    .sorted(Comparator.comparingDouble(Employee::getSalary))
                    .map(Employee::getName)
                    .collect(Collectors.toList());
            System.out.println("按工资由低到高排序的员工名字: " + list);

            // 9. 将员工按照工资由高到低排序，显示名字
            List<String> list1 = employees.stream()
                    .sorted(Comparator.comparingDouble(Employee::getSalary).reversed())
                    .map(Employee::getName)
                    .collect(Collectors.toList());
            System.out.println("按工资由高到低排序的员工名字: " + list1);

            // 10. 将员工按照工资由低到高排序，显示名字
            List<String> list2 = employees.stream()
                    .sorted(Comparator.comparingDouble(Employee::getSalary))
                    .map(Employee::getName)
                    .collect(Collectors.toList());
            System.out.println("按工资由低到高排序的员工名字: " + list2);
        }
    }


